package com.neusoft.elmboot.service.impl;
import com.neusoft.elmboot.Vo.BussinessVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neusoft.elmboot.Vo.OrdersVo;
import com.neusoft.elmboot.Vo.UserVo;
import com.neusoft.elmboot.mapper.BusinessMapper;
import com.neusoft.elmboot.mapper.OrdersMapper;
import com.neusoft.elmboot.po.BusinessEntity;
import com.neusoft.elmboot.po.OrdersEntity;
import com.neusoft.elmboot.service.OrdersService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper,OrdersEntity> implements OrdersService{
    @Autowired
    private OrdersMapper ordersMapper;

    @Autowired
    private BusinessMapper businessMapper;

    @Override
    public List<OrdersVo> getByUserId(Long userId) {

        LambdaQueryWrapper<OrdersEntity> lqw = new LambdaQueryWrapper<>();
        lqw.eq(OrdersEntity::getUserId, userId);

        List<OrdersEntity> ordersEntityList = this.baseMapper.selectList(lqw);
        List<OrdersVo> ordersVoList = new ArrayList<>();
        for (OrdersEntity ordersEntity: ordersEntityList) {
            BusinessEntity businessEntity = businessMapper.selectById(ordersEntity.getBusinessId());
            OrdersVo ordersVo = new OrdersVo();
            BussinessVo bussinessVo = new BussinessVo();
            BeanUtils.copyProperties(businessEntity,bussinessVo);

            BeanUtils.copyProperties(ordersEntity, ordersVo);
            ordersVo.setBussinessVo(bussinessVo);
            ordersVoList.add(ordersVo);
        }
        return ordersVoList;

    }
}
